import { createRouter, createWebHistory } from 'vue-router'
import type { RouteRecordRaw } from 'vue-router'

import Login from '../components/Login.vue'
import Users from '../components/Users.vue'
import Roles from '../components/Roles.vue'
import Register from '../components/Register.vue' // 新增注册组件导入

const routes: RouteRecordRaw[] = [
  { path: '/', redirect: '/login' }, // 首页跳转到登录页
  { path: '/login', name: 'Login', component: Login },
  { path: '/register', name: 'Register', component: Register },
  { path: '/users', name: 'Users', component: Users },
  { path: '/roles', name: 'Roles', component: Roles },
  { path: '/:pathMatch(.*)*', redirect: '/login' } // 404 跳登录页
]

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes
})

export default router
